home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261c.zoo / objects / Collecting.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  6.4 KB  |  196 lines

  1. /* Protocol for Objective-C objects that hold collections of elements.
  2.    Copyright (C) 1993,1994 Free Software Foundation, Inc.
  3.  
  4.    Written by:  R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
  5.    Date: May 1993
  6.  
  7.    This file is part of the GNU Objective C Class Library.
  8.  
  9.    This library is free software; you can redistribute it and/or
  10.    modify it under the terms of the GNU Library General Public
  11.    License as published by the Free Software Foundation; either
  12.    version 2 of the License, or (at your option) any later version.
  13.    
  14.    This library is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.    Library General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU Library General Public
  20.    License along with this library; if not, write to the Free
  21.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */ 
  23.  
  24. /* The <Collecting> protocol is root of the collection protocol heirarchy. 
  25.  
  26.    The <Collecting> protocol defines the most general interface to a
  27.    collection of elements.  Elements can be added, removed, and replaced.
  28.    The contents can be tested, enumerated, and enumerated through various
  29.    filters.  Elements may be objects, or any C type included in the 
  30.    "elt" union given in elt.h, but all elements of a collection must be of
  31.    the same C type.
  32. */
  33.  
  34. #ifndef __Collecting_h_INCLUDE_GNU
  35. #define __Collecting_h_INCLUDE_GNU
  36.  
  37. #include <objects/stdobjects.h>
  38. #include <objc/Object.h>
  39. #include <objects/elt.h>
  40.  
  41. @protocol Collecting
  42.  
  43. // INITIALIZING;
  44. - init;
  45. - initWithContentsOf: (id <Collecting>)aCollection;
  46.  
  47. // FREEING;
  48. - free;
  49. - freeObjects;
  50.  
  51. // ADDING;
  52. - addObject: newObject;
  53. - addObjectIfAbsent: newObject;
  54. - addContentsOf: (id <Collecting>)aCollection;
  55. - addContentsOfIfAbsent: (id <Collecting>)aCollection;
  56. - addObjectsCount: (unsigned)count, ...;
  57.  
  58. // REMOVING;
  59. - removeObject: oldObject;
  60. - removeObject: oldObject ifAbsentCall: (id(*)(arglist_t))excFunc;
  61. - removeAllOccurrencesOfObject: oldObject;
  62. - removeContentsIn: (id <Collecting>)aCollection;
  63. - removeContentsNotIn: (id <Collecting>)aCollection;
  64. - uniqueContents;
  65. - empty;
  66.  
  67. // REPLACING;
  68. - replaceObject: oldObject with: newObject;
  69. - replaceObject: oldObject with: newObject 
  70.     ifAbsentCall:(id(*)(arglist_t))excFunc;
  71. - replaceAllOccurrencesOfObject: oldObject with: newObject;
  72.  
  73. // TESTING;
  74. - (BOOL) isEmpty;
  75. - (BOOL) includesObject: anObject;
  76. - (BOOL) isSubsetOf: (id <Collecting>)aCollection;
  77. - (BOOL) isDisjointFrom: (id <Collecting>)aCollection;
  78. - (int) compare: anObject;
  79. - (BOOL) isEqual: anObject;
  80. - (BOOL) contentsEqual: (id <Collecting>)aCollection;
  81. - (unsigned) count;
  82. - (unsigned) occurrencesOfObject: anObject;
  83. - (BOOL) trueForAllObjectsByCalling: (BOOL(*)(id))aFunc;
  84. - (BOOL) trueForAnyObjectsByCalling: (BOOL(*)(id))aFunc;
  85. - detectObjectByCalling: (BOOL(*)(id))aFunc;
  86. - detectObjectByCalling: (BOOL(*)(id))aFunc 
  87.     ifNoneCall: (id(*)(arglist_t))excFunc;
  88. - maxObject;
  89. - maxObjectByCalling: (int(*)(id,id))aFunc;
  90. - minObject;
  91. - minObjectByCalling: (int(*)(id,id))aFunc;
  92.  
  93. // ENUMERATING
  94. - (void*) newEnumState;
  95. - (BOOL) getNextObject:(id *)anObjectPtr withEnumState: (void**)enumState;
  96. - freeEnumState: (void**)enumState;
  97. - withObjectsCall: (void(*)(id))aFunc;
  98. - withObjectsCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
  99. - injectObject: initialArgObject byCalling:(id(*)(id,id))aFunc;
  100. - makeObjectsPerform: (SEL)aSel;
  101. - makeObjectsPerform: (SEL)aSel with: argObject;
  102.  
  103. // ENUMERATING WHILE CHANGING CONTENTS;
  104. - safeMakeObjectsPerform: (SEL)aSel;
  105. - safeMakeObjectsPerform: (SEL)aSel with: argObject;
  106. - safeWithObjectsCall: (void(*)(id))aFunc;
  107. - safeWithObjectsCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
  108.  
  109. // FILTERED ENUMERATING;
  110. - withObjectsTrueByCalling: (BOOL(*)(id))testFunc 
  111.     call: (void(*)(id))destFunc;
  112. - withObjectsFalseByCalling: (BOOL(*)(id))testFunc 
  113.     call: (void(*)(id))destFunc;
  114. - withObjectsTransformedByCalling: (id(*)(id))transFunc
  115.     call: (void(*)(id))destFunc;
  116.  
  117. // COPYING 
  118. - emptyCopy;
  119. - emptyCopyAs: (id <Collecting>)aCollectionClass;
  120. - shallowCopy;
  121. - shallowCopyAs: (id <Collecting>)aCollectionClass;
  122. - copy;
  123. - copyAs: (id <Collecting>)aCollectionClass;
  124. - species;
  125.  
  126. // ARCHIVING;
  127. - write: (TypedStream*)aStream;
  128. - read: (TypedStream*)aStream;
  129.  
  130.  
  131. // NON-OBJECT ELEMENT METHOD NAMES;
  132.  
  133. // INITIALIZING;
  134. - initWithType:(const char *)contentEncoding;
  135.  
  136. // ADDING;
  137. - addElement: (elt)newElement;
  138. - addElementIfAbsent: (elt)newElement;
  139. - addElementsCount: (unsigned)count, ...;
  140.  
  141. // REMOVING;
  142. - (elt) removeElement: (elt)oldElement;
  143. - (elt) removeElement: (elt)oldElement 
  144.     ifAbsentCall: (elt(*)(arglist_t))excFunc;
  145. - removeAllOccurrencesOfElement: (elt)oldElement;
  146.  
  147. // REPLACING;
  148. - (elt) replaceElement: (elt)oldElement with: (elt)newElement;
  149. - (elt) replaceElement: (elt)oldElement with: (elt)newElement
  150.     ifAbsentCall: (elt(*)(arglist_t))excFunc;
  151. - replaceAllOccurrencesOfElement: (elt)oldElement with: (elt)newElement;
  152.  
  153. // TESTING;
  154. - (BOOL) includesElement: (elt)anElement;
  155. - (unsigned) occurrencesOfElement: (elt)anElement;
  156. - (elt) detectElementByCalling: (BOOL(*)(elt))aFunc;
  157. - (elt) detectElementByCalling: (BOOL(*)(elt))aFunc 
  158.     ifNoneCall: (elt(*)(arglist_t))excFunc;
  159. - (elt) maxElement;
  160. - (elt) maxElementByCalling: (int(*)(elt,elt))aFunc;
  161. - (elt) minElement;
  162. - (elt) minElementByCalling: (int(*)(elt,elt))aFunc;
  163. - (BOOL) trueForAllElementsByCalling: (BOOL(*)(elt))aFunc;
  164. - (BOOL) trueForAnyElementsByCalling: (BOOL(*)(elt))aFunc;
  165. - (const char *) contentType;
  166. - (BOOL) contentsAreObjects;
  167. - (int(*)(elt,elt)) comparisonFunction;
  168.  
  169. // ENUMERATING;
  170. - (BOOL) getNextElement:(elt *)anElementPtr withEnumState: (void**)enumState;
  171. - withElementsCall: (void(*)(elt))aFunc;
  172. - withElementsCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag;
  173. - (elt) injectElement: (elt)initialElement byCalling: (elt(*)(elt,elt))aFunc;
  174.  
  175. // ENUMERATING WHILE CHANGING CONTENTS;
  176. - safeWithElementsCall: (void(*)(elt))aFunc;
  177. - safeWithElementsCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag;
  178.  
  179. // FILTERED ENUMERATING;
  180. - withElementsTrueByCalling: (BOOL(*)(elt))testFunc 
  181.     call: (void(*)(elt))destFunc;
  182. - withElementsFalseByCalling: (BOOL(*)(elt))testFunc 
  183.     call: (void(*)(elt))destFunc;
  184. - withElementsTransformedByCalling: (elt(*)(elt))transFunc
  185.     call: (void(*)(elt))destFunc;
  186.  
  187.  
  188. // BE SURE WE HAVE THESE METHODS NORMALLY PROVIDED BY Object;
  189. + alloc;
  190. - (BOOL) respondsTo: (SEL)aSel;
  191. - (BOOL) conformsTo: aProtocolObject;
  192.  
  193. @end
  194.  
  195. #endif /* __Collecting_h_INCLUDE_GNU */
  196.